﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using Small.Util.Reflection;

namespace Small.UI
{
   public static class HtmlInput
    {

       public static MvcHtmlString HtmlInput1(this HtmlHelper helper, 
                                   string id, string validateAttribute,
                                   string value = null, string name = null,
                                   object htmlAttribute = null)
       {

           StringBuilder builder = new StringBuilder();


           builder.Append("<input type='text' ");
           if (!string.IsNullOrEmpty(id))
           {
               builder.Append(string.Format(" id='{0}'", id));
           }
           if (string.IsNullOrEmpty(value))
           {
               value = "";
           }

           builder.Append(string.Format("value='{0}'", value));
           if (htmlAttribute != null)
           {
               foreach (var item in AnonymousProperties.GetAnonymousInfomation(htmlAttribute))
               {
                   builder.Append(" " + item.Name + "=\"" + item.Value + "\"");

               }
           }

           builder.Append(" />\r\n");
           return new MvcHtmlString(builder.ToString());
       }
    }
}
